﻿using AbpApplication.AppServices;
using Hangfire;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Reconstruct_Zhbs.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class HangFireController : ControllerBase
    {



        [HttpPost]
        public bool ClosePolling()
        {
            try
            {
                RecurringJob.RemoveIfExists("Polling_OutBound");
                RecurringJob.RemoveIfExists("Polling_TaskAgv_OutBound");
                RecurringJob.RemoveIfExists("Polling_TaskOrder");
                RecurringJob.RemoveIfExists("Polling_UpdateQuantity");
                RecurringJob.RemoveIfExists("Polling_ClearConveyorline");
                RecurringJob.RemoveIfExists("Polling_expireTaskOrder");
                return true;
            }
            catch
            {
                return false;
            }
         
        }
        [HttpPost]
        public bool OpenPolling()
        {
            try
            {
                RecurringJob.AddOrUpdate<IBaseService>("Polling_OutBound", job => job.Polling_OutBound(), Cron.Minutely);// "0/30 * * * * ?"Cron.MinuteInterval(1)       
                RecurringJob.AddOrUpdate<IBaseService>("Polling_TaskOrder", job => job.Polling_TaskOrder(), Cron.MinuteInterval(1));
                RecurringJob.AddOrUpdate<IBaseService>("Polling_TaskAgv_OutBound", job => job.Polling_TaskAgv_OutBound(), Cron.MinuteInterval(1));
                RecurringJob.AddOrUpdate<IBaseService>("Polling_UpdateQuantity", job => job.Polling_UpdateQuantity(), Cron.Daily(4), TimeZoneInfo.Local);
                RecurringJob.AddOrUpdate<IBaseService>("Polling_ClearConveyorline", job => job.Polling_ClearConveyorline(), Cron.Daily(4), TimeZoneInfo.Local);
                RecurringJob.AddOrUpdate<IBaseService>("Polling_expireTaskOrder", job => job.Polling_expireTaskOrder(), Cron.MinuteInterval(20));
                RecurringJob.AddOrUpdate<IBaseService>("IsReplenishment", job => job.IsReplenishment(), Cron.HourInterval(2));
                RecurringJob.AddOrUpdate<IBaseService>("test", job => job.test(), "*/10 * * * * *");
                return true;
            }
            catch
            {
                return false;
            }    
        }
        [HttpPost]
        public bool OpenPollingAGv()
        {

            return true;
        }
    }
}
